﻿<UserControl xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"  x:Class="DemoNYTimes.CongressPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:nyt="clr-namespace:NYTimes;assembly=NYTimesSilverlightKit"
    xmlns:nytvc="clr-namespace:NYTimes.ValueConverters;assembly=NYTimesSilverlightKit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
	d:DesignWidth="640" d:DesignHeight="480" FontFamily="Trebuchet MS">
    <UserControl.Resources>
    	<nyt:MembersOfCongress x:Key="MembersOfCongressDS" d:IsDataSource="True" Chamber="House" CongressNumber="111"/>
        <nyt:CongressMemberBioAndRole x:Key="MemberBio" d:IsDataSource="True"/>
        <nytvc:CongressMemberConverter x:Key="CongressMemberConverter"/>
        <nytvc:CollapsedIfNullConverter x:Key="CollapsedIfNullConverter"/>
        <nytvc:ChamberConverter x:Key="ChamberConverter"/>
		<nytvc:DateTimeConverter x:Key="DateTimeConverter" d:IsDataSource="True"/>
        <DataTemplate x:Key="RoleTemplate">
        	<Grid>
        		<StackPanel Margin="0,0,13,0">
        			<StackPanel Height="Auto" Width="Auto" Orientation="Horizontal">
        				<TextBlock Margin="0,0,4,0" Text="{Binding Path=Title}" 
                                   TextWrapping="NoWrap"/>
        				<TextBlock Margin="0,0,4,0" Text="{Binding Path=State}" 
                                   TextWrapping="NoWrap"/>
        				<TextBlock Text=" District " TextWrapping="Wrap" 
                         Visibility="{Binding District, Converter={StaticResource CollapsedIfNullConverter}}"/>
        				<TextBlock Text="{Binding Path=District}" TextWrapping="NoWrap" 
                         Visibility="{Binding District, Converter={StaticResource CollapsedIfNullConverter}}"/>
        				<TextBlock Text=" (" TextWrapping="Wrap"/>
        				<TextBlock 
                         Text="{Binding Converter={StaticResource DateTimeConverter}, ConverterParameter=d, Path=StartDate}" 
                         TextWrapping="Wrap"/>
        				<TextBlock Text=" - " TextWrapping="Wrap"/>
        				<TextBlock 
                         Text="{Binding EndDate, Converter={StaticResource DateTimeConverter}, ConverterParameter=d}" 
                         TextWrapping="Wrap"/>
        				<TextBlock Text=")" TextWrapping="Wrap"/>
        			</StackPanel>
        			<StackPanel Height="Auto" Orientation="Horizontal" 
                     Visibility="{Binding MissedVotePercent, Converter={StaticResource CollapsedIfNullConverter}}">
        				<TextBlock Text="Missed Votes: " TextWrapping="NoWrap"/>
        				<TextBlock Text="{Binding Path=MissedVotePercent}" TextWrapping="Wrap"/>
                        <TextBlock Text="%" TextWrapping="NoWrap"/>
        			</StackPanel>
        			<StackPanel Height="Auto" Orientation="Horizontal" 
                     Visibility="{Binding VotesWithPartyPercent, Converter={StaticResource CollapsedIfNullConverter}}">
        				<TextBlock Text="Votes with Party:" TextWrapping="Wrap"/>
        				<TextBlock Text="{Binding Path=VotesWithPartyPercent}" 
                                   TextWrapping="Wrap"/>
                        <TextBlock Text="%" TextWrapping="NoWrap"/>
        			</StackPanel>
                    <TextBlock Text="Committees"/>
                    <ListBox ItemsSource="{Binding Committees}" DisplayMemberPath="Name"/>
        		</StackPanel>
        	</Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="4*"/>
        </Grid.ColumnDefinitions>
        <StackPanel DataContext="{StaticResource MembersOfCongressDS}" Margin="4,4,4,4">
            <RadioButton Content="House" 
             IsChecked="{Binding Chamber, Mode=TwoWay, Converter={StaticResource ChamberConverter}, ConverterParameter=House}" />
            <RadioButton Content="Senate" 
             IsChecked="{Binding Chamber, Mode=TwoWay, Converter={StaticResource ChamberConverter}, ConverterParameter=Senate}" />
            <StackPanel Orientation="Horizontal">
                <dataInput:Label Content="Congress:" VerticalAlignment="Center"/>
                <inputToolkit:NumericUpDown DecimalPlaces="0" IsEditable="True" Minimum="80" 
                    Value="{Binding CongressNumber}" Maximum="111"/>
            </StackPanel>
        </StackPanel>
        <ListBox x:Name="CongressMembers" Grid.Row="1" 
                 ItemsSource="{Binding Members, Source={StaticResource MembersOfCongressDS}}" 
                 SelectedItem="{Binding MemberId, Mode=TwoWay, Source={StaticResource MemberBio}, Converter={StaticResource CongressMemberConverter}}" 
                 Margin="4,4,4,4">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding FirstName}"/>
                        <TextBlock Text=" "/>
                        <TextBlock Text="{Binding MiddleName}"/>
                        <TextBlock Text=" "/>
                        <TextBlock Text="{Binding LastName}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox Grid.Column="1" Grid.Row="1" x:Name="Roles" 
                 ItemsSource="{Binding Roles, Source={StaticResource MemberBio}}" 
                 ItemTemplate="{StaticResource RoleTemplate}" Margin="4,4,4,4"/>
        <TextBlock Grid.Row="2" Text="{Binding Status, Source={StaticResource MembersOfCongressDS}}"/>
        <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Status, Source={StaticResource MemberBio}}"/>
    </Grid>
</UserControl>
